// Source File Name:   OnLine.java

package com.rhb.ca.web.online;

import java.io.Serializable;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

public class OnLine implements Serializable{
    protected String sessionID;
    protected String touchIP;
    protected String touchUrl;
    protected long touchTime;
    private static int OVERTIMELIMIT = 30;

    public OnLine(){
        this.sessionID = "";
        this.touchIP = "";
        this.touchUrl = "";
        this.touchTime = (new Date()).getTime();
    }

    public void init(OnLine ol){
        this.sessionID = ol.sessionID;
        this.touchIP = ol.touchIP;
        this.touchUrl = ol.touchUrl;
        this.touchTime = ol.touchTime;
    }

    public void setSessionID(String str){sessionID = str; }
    public String getSessionID(){return sessionID;}

    public void setTouchIP(String str){touchIP = str;}
    public String getTouchIP(){return touchIP;}

    public void setTouchUrl(String str){touchUrl = str;}
    public String getTouchUrl(){return touchUrl;}

    public void setTouchTime(long str){touchTime = str;}
    public String getTouchTime(){
        //DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
        dateFormat.setTimeZone(TimeZone.getTimeZone("GMT+8"));
        return dateFormat.format(new Date(this.touchTime + 1));
    }

    public String toString(){
        StringBuffer tmp = new StringBuffer();
        tmp.append("touchIP:");
        tmp.append(touchIP);
        tmp.append(",");
        tmp.append("touchUrl:");
        tmp.append(touchUrl);
        tmp.append(",");
        tmp.append("touchTime:");
        tmp.append(getTouchTime());
        return tmp.toString();
    }

    public boolean isOvertime(){
		return ((new Date()).getTime()-this.touchTime)>((long)OVERTIMELIMIT*(long)60*(long)1000)?true:false;
    }

}
